//
//  AXMyDiseaseManageVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/12.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXMyDiseaseManageVC.h"
#import "UIView+SDAutoLayout.h"
#import "AXMyDiseaseManageModel.h"
#import "AXMyDiseaseManageCell.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "UIViewController+HBD.h"
#import "AXMyAddDiseaseManageVC.h"


@interface AXMyDiseaseManageVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) NSMutableArray<AXMyDiseaseManageModel*> *modelsArray;
@property (nonatomic , strong) UITableView *tableView;
@property (nonatomic , strong) UIView *footerView;

@end

@implementation AXMyDiseaseManageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    self.view.backgroundColor = [UIColor whiteColor];
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    
    /** tableview 的表尾按钮 */
    self.tableView.tableFooterView = _footerView;
    _footerView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = _footerView;
    
    
    
}

- (void)creatView {
    
    _footerView = [[UIView alloc]init];
    
    UIButton *saveBtn = [[UIButton alloc]init];
    saveBtn.backgroundColor = COLOR_GREEN;
    saveBtn.cornerRadius = 5;
    [saveBtn setTitle:@"新增" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
    [self.footerView addSubview:saveBtn];
    
    
    saveBtn.sd_layout
    .leftSpaceToView(self.footerView, 50)
    .topSpaceToView(_footerView, 56)
    .widthIs(SCREEN_WIDTH-100)
    .heightIs(44);
    
    self.tableView = [[UITableView alloc]init];
    self.tableView.backgroundColor = [UIColor whiteColor];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    _footerView.frame = CGRectMake(0, 56, SCREEN_WIDTH, 100);
    self.tableView.tableFooterView = self.footerView;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXMyDiseaseManageCell class] forCellReuseIdentifier:[AXMyDiseaseManageCell reuseID]];
    [self.view addSubview:self.tableView];
}

- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, Hn)
    .widthIs(SCREEN_WIDTH)
    .heightIs(TableViewHeight);
}


- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    /** 搜索 */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"病害管理";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_FOURTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitleColor:COLOR_ORG forState:UIControlStateNormal];
    rightBtn.titleLabel.font = FONT_FOURTEEN;
    [rightBtn setTitle:@"防治方法" forState:UIControlStateNormal];
    rightBtn.frame = CGRectMake(0, 0, 30, 30);
    [rightBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView: rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)add:(UIButton *)btn {
    
    AXMyAddDiseaseManageVC *vc = [[AXMyAddDiseaseManageVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}




#pragma mark - tableViewDelegate & tableViewDatasorce

//分区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    
    return view;
    
    
}
/** 分区的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return 10;
    
}

//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[AXMyDiseaseManageCell class] contentViewWidth:SCREEN_WIDTH];
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    AXMyDiseaseManageCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMyDiseaseManageCell reuseID] forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    //管理按钮的事件
    
    
    
    return cell;
    
    
}




@end






